package com.lagou.client;

import com.lagou.component.ConsumerService;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import java.io.IOException;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
@EnableDubbo(scanBasePackages = "com.lagou.component")
@PropertySource("classpath:dubbo-consumer.properties")
@ComponentScan(basePackages = "com.lagou.component")
public class ConsumerMain {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ConsumerMain.class);
        applicationContext.start();
        ConsumerService apiComponent = applicationContext.getBean(ConsumerService.class);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(10,20,10, TimeUnit.SECONDS,new LinkedBlockingQueue<>());
        while (true){
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            threadPoolExecutor.execute(()->{
                apiComponent.domethodA("111");
                apiComponent.domethodB("222");
                apiComponent.domethodC("333");
            });
        }
    }
}
